$(function(){
	
	//点击一级显示二级三级
	$('a[name="oneProductCategory"]').click(function(){	
		var oneProductCategoryId = $(this).attr("data-id");
		$(".category-content").html('<div class="loading middle">'
			+'<img src="http://oaats41rf.bkt.clouddn.com/loading.gif"/>加载中...'
		+'</div>');
		
		$.ajax({
			type:"get",
			url:base_url+"customer/getClassifyMsgByOneId",
			data:{"oneProductCategoryId":oneProductCategoryId},
			success:function(data){
				var html ="";
				for(var i=0;i<data.length;i++){
					var threeProductCategories = data[i].threeProductCategories;
					html = html
					+ '<div class="category-second-list">'
					+'<h4>'+data[i].twoProductCategory.productCategoryName+'</h4>'
					+'<ul class="category-second-list-content clearfloat">';
					for(var j=0;j<threeProductCategories.length;j++){
						html = html
							+'<li>'
							+'<a href="#" >'
							+'<img data-src="'+threeProductCategories[j].productCategoryUrl+'" name="threeProductCategory"  data-id="'+threeProductCategories[j].productCategoryId+'" data-name="'+threeProductCategories[j].productCategoryName+'"class="lazy" data-load="false" />'
							+'<span>'+threeProductCategories[j].productCategoryName+'</span>'
							+'</a>'
							+'</li>';
					}
					html = html + '</ul></div>';
				}
				$(".category-content").hide().html(html).fadeIn();
				lazyLoad($(".lazy[data-load='false']"));
			},
			error:function(){
			}
		});
	});
	
		//点击三级分类跳到商品展示
	$(".category-content").on("click",'img[name="threeProductCategory"]',function(){
		var threeCategoryId = $(this).attr("data-id");
		var threeCategoryName = $(this).attr("data-name");
		var url = base_url + "customer/getProductCategoryMsges";
		var json = {
				"threeCategoryId":threeCategoryId,
				"threeCategoryName":threeCategoryName
		}
		var jsonStr = JSON.stringify(json);
		window.location.href = base_url + "customer/getProductCategoryMsges?jsonStr="+jsonStr;
	});

	//侧边栏动作
	$("#leftBar").on("tap","li",function(){
		var y  = this.offsetTop;
		var bar = $("#leftBar");
		bar.find("li").removeClass("active");
		$(this).addClass("active");
		bar.animate({scrollTop:y},300)
	})
});
window.onscroll = function(){
	lazyLoad($(".lazy[data-load='false']"));
};